using MyTimer;
using UnityEngine;
using UnityEngine.Experimental.Rendering.Universal;

public class FlashLight : MonoBehaviour
{
    private Light2D m_light;

    [SerializeField]
    private float t_flash;
    [SerializeField]
    private float t_wave;
    [SerializeField]
    private float intensity_max;
    private LinearTransformation intensityChange;
    private SineWave radiusChange;

    private float radius_default;
    private float radius_delta;

    private void Awake()
    {
        m_light = GetComponent<Light2D>();
        radius_default = m_light.pointLightOuterRadius;
        radius_delta = radius_default * 0.02f;
        intensityChange = new LinearTransformation();
        radiusChange = new SineWave();
    }

    private void Update()
    {
        if (intensityChange.Completed)
            m_light.intensity = intensityChange.Target;
        else
            m_light.intensity = intensityChange.Current;
        m_light.pointLightOuterRadius = radiusChange.Current;
    }

    private void OnEnable()
    {
        intensityChange.Initialize(0f, intensity_max, t_flash);
        radiusChange.Initialize(radius_default - radius_delta, radius_default + radius_delta, t_wave);
    }

    private void OnDisable()
    {
        intensityChange.Paused = true;
        radiusChange.Paused = true;
    }
}
